package Thread;

//买火车票
public class demo3 implements Runnable {

	private int ticketNums = 10;

	@Override
	public void run() {
		while (true) {
			if (ticketNums <= 0)
				break;
			// 模拟延迟:放大问题的发生性
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName() + "拿到了" + ticketNums-- + "票");
		}
	}

	public static void main(String[] args) {
		// 创建runnable接口的实现类对象
		demo3 b = new demo3();
		// 创建线程对象，通过线程对象来开启我们的线程，代理
		new Thread(b, "a").start();
		new Thread(b, "b").start();
		new Thread(b, "c").start();
	}
}
